//
//  RelatedIssuesView.m
//  安好
//
//  Created by lianchuang on 14/12/17.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "RelatedIssuesView.h"
#import "RelatedViewCell.h"
@implementation RelatedIssuesView
- (void)reloadMytableview:(NSArray *)array WithKeywords:(NSString *)keyword
{
    self.tableview.delegate=self;
    self.tableview.dataSource=self;
    self.infoArray=[[NSArray alloc]initWithArray:array];
    self.keyword=keyword;
    self.tableview.backgroundColor=[ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    self.tableview.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.tableview reloadData];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (self.infoArray.count>=4) {
        return 5;
    }else
    {
        return self.infoArray.count;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *indentifier=@"cell";
    RelatedViewCell *cell=[tableView dequeueReusableCellWithIdentifier:indentifier];
    if (!cell) {
        if (kScreenWidth==414) {
            cell=[[[NSBundle mainBundle]loadNibNamed:@"RelatedViewCell" owner:self options:nil] lastObject];
        }else{
            cell=[[[NSBundle mainBundle]loadNibNamed:@"RelatedViewCell" owner:self options:nil] firstObject];

        }
    }
    if (indexPath.row==0) {
        cell.content.text=@"还没有医生回复，您可以先看看...";
        cell.pushImage.hidden=YES;
        cell.backView.backgroundColor=[UIColor clearColor];
        cell.lineView.hidden=YES;
    }else
    {
        cell.lineView.hidden=NO;
        cell.backView.backgroundColor=[UIColor whiteColor];
        cell.pushImage.hidden=NO;
        NSString *content=[[self.infoArray objectAtIndex:indexPath.row-1] valueForKey:@"content"];
        
        NSString *content1=[content stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:content1];

        NSArray *keyarray=[self.keyword componentsSeparatedByString:@"|"];
        for (int i=0; i<keyarray.count; i++) {
            NSRange range=[[[self.infoArray objectAtIndex:indexPath.row-1] valueForKey:@"content"] rangeOfString:[keyarray objectAtIndex:i]];
            [str addAttribute:NSForegroundColorAttributeName value:[ClassMethodsViewController colorWithHexString:NACIGATIONBAR_BACKGROUNDCOLOR_16] range:range];
        }
        cell.content.attributedText=str;
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
    }
    else{
        if (self.relatedDelegate&&[self.relatedDelegate respondsToSelector:@selector(clickRelatedIssuse:)]) {
            [self.relatedDelegate clickRelatedIssuse:[self.infoArray objectAtIndex:indexPath.row-1]];
        }
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (kScreenWidth==414) {
        return 53;
    }
    return 44;
}
@end
